define([
  ELMP.resource('utils/dayjs.js', 'lib'),
],
  function (dayjs) {
    return {
      // 字典过滤
      dictFilter (value, dictType, label = 'displayName') {
        if (!value) return value
        if (!Array.isArray(value)) {
          value = value.split(',')
        }
        const list = $.dict.values(dictType)
        value = value.map(item => {
          const dict = list.find(dict => {
            return dict.value === item
          })
          return dict?.[label] || item
        })
        return value.join(',')
      },
      sexFilter (sex) {
        const map = {
          0: '女',
          1: '男'
        }
        return map[sex]
      },
      dayjsFilter (date, formatter = 'YYYY-MM-DD') {
        if (!date) return ''
        return dayjs(date).format(formatter)
      },
      userFilter (id, data) {
        let userList = []
        if (typeof data === 'function') {
          userList = data()
        } else if (Array.isArray(data)) {
          userList = data
        }
        const user = userList?.find(item => item.id === id)
        return user?.displayName || id
      }
    }
  })